

import pymysql
from faker import Faker

# pymysql 连接数据库 发送sql语句 获取sql的执行结果
if __name__ == '__main__':
    #连接对象
    conn = pymysql.connections.Connection(host="127.0.0.1", port=3306, user="root", passwd="root",db="shop")

    # # 定义sql
    # sql = "select * from user where username = %s and password = %s;"
    #
    # # 获取游标对象
    # cursor = conn.cursor()
    #
    # #执行sql
    # result = cursor.execute(sql,["wangwu","123"])
    #
    # #查询所有
    # row = cursor.fetchmany(10)
    # print(row)

    sql= "insert into user(username,password) values(%s,%s)"

    cursor = conn.cursor()

    result = cursor.execute(sql,("admin124","admin123"))

    conn.commit()

    #关闭连接
    cursor.close()
    conn.close()

